﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using InSafetyAirClient.InSafetyAirService;

namespace InSafetyAirClient.GUI.AccountPerson
{
    public partial class CreateAP : UserControl
    {
        
        public CreateAP()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Person person = new Person();
            Account account = new Account();
            person.fName = textBox1.Text;
            person.sName = textBox2.Text;
            if (comboBox3.SelectedText.Equals("male"))
                person.gender = true;
            else
                person.gender = false;
            person.passportNo = textBox3.Text;
            person.phone = textBox9.Text;
            person.address = textBox4.Text;
            account.username = textBox5.Text;
            account.password = textBox6.Text;
            account.email = textBox8.Text;
            switch (comboBox10.SelectedText)
            {
                case "0":
                    {
                        account.access = 0;
                        break;
                    }
                case "1":
                    {
                        account.access = 1;
                        break;
                    }
            }
            person = (Person)ServiceSingle.Instance.getService().AddToDatabase(person);
            account.personId = person.personId;
            ServiceSingle.Instance.getService().createAccount(person, account.username, account.password, account.email, account.access);
        }
    }
}
